home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / dalib / pvm3 / section1.c < prev    next >
C/C++ Source or Header  |  1993-04-30  |  28KB  |  934 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Aug 92                                                   *
  6. *  Last Update : Apr 93                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB                                       *
  9. *                                                                         *
  10. *  Module      : section1.c                                               *
  11. *                                                                         *
  12. *  Function    : Sending/Receiving a section of a distributed array       *
  13. *                                                                         *
  14. *  Export :    ONLY INTERNAL USE IN DALIB                                 *
  15. *                                                                         *
  16. *  void dalib_setup_sectionk (size, N1, x1, y1, ..., Nk, xk, yk)          *
  17. *  int size N1, x1, y1, N2, x2, ..., Nk, xk, yk;                          *
  18. *                                                                         *
  19. *  void dalib_send_sectionk (to, a)                        k = 1,...,4    *
  20. *  int to; unsigned char *a;                                              *
  21. *                                                                         *
  22. *  void dalib_recv_sectionk (from, a)                      k = 1,...,4    *
  23. *  int from; unsigned char *a;                                            *
  24. *                                                                         *
  25. *  void dalib_copy_sectionk (to, a)                        k = 1,...,4    *
  26. *  unsigned char *to; unsigned char *a;                                   *
  27. *                                                                         *
  28. **************************************************************************/
  29.  
  30. # undef DEBUG
  31.  
  32. #include "system.h"
  33.  
  34.      /*********************************************************
  35.      *                                                        *
  36.      *  GLOBALS for whole array and considered section        *
  37.      *                                                        *
  38.      *********************************************************/
  39.  
  40. # define DIM 4       /* maximal supported dimension */
  41.  
  42. /* global data of the distributed array */
  43.  
  44. int a_N [DIM];
  45. int a_rank, a_size;
  46.  
  47. /* global data of the section in the distributed array */
  48.  
  49. int sc_x[DIM];      /* bounds of the section */
  50. int sc_y[DIM];
  51. int sc_n[DIM];      /* shape of the section */
  52.  
  53. int sc_size;        /* size of the whole section */
  54.  
  55. /* global data for looping through the section */
  56.  
  57. int sc_ptr;       /* offset to first element in section */
  58. int sc_length;    /* length of section in bytes */
  59.  
  60. int sc_loops;
  61. int sc_times[DIM];  /* iterations of the corresponding loop */
  62. int sc_inc  [DIM];  /* pointer increment for the loop       */
  63. int sc_loops;     /* number of loops for traversing section */
  64.  
  65.      /*********************************************************
  66.      *                                                        *
  67.      *  Computing the loops of a given section                *
  68.      *                                                        *
  69.      *********************************************************/
  70.  
  71. void dalib_section_loops ()
  72.  
  73. { int i, lv, removed, errors;
  74.  
  75.   /* normalize and compute shape of the section */
  76.  
  77. #ifdef DEBUG
  78.   printf ("dalib_section_loops called with rank = %d\n",a_rank);
  79. #endif
  80.  
  81.   errors  = 0;
  82.   sc_size = 1;
  83.   for (i=0; i<a_rank; i++)
  84.     { sc_x[i] = sc_x[i] - 1;
  85.       sc_y[i] = sc_y[i] - 1;
  86.       sc_n[i] = sc_y[i] - sc_x[i] + 1;
  87. #ifdef DEBUG
  88.   printf ("dalib_section_loops , i = %d, x = %d, y = %d, n = %d\n",
  89.            i, sc_x[i], sc_y[i], sc_n[i]);
  90. #endif
  91.       if (sc_n[i] <= 0)
  92.         { printf ("Section of rank = %d, dim %d illegal: %d - %d\n",
  93.                   a_rank, i+1, sc_x[i], sc_y[i]);
  94.           errors += 1;
  95.         }
  96.       sc_size *= sc_n[i];
  97.     }
  98.   if (errors > 0) exit (-1);
  99.  
  100.   /*  Set up the initial loops (will be optimized later)
  101.  
  102.      loops   times     inc   
  103.        1      n1        1
  104.        2      n2        N1
  105.        3      n3        N1 * N2
  106.        4      n4        N1 * N2 * N3      */
  107.  
  108.   for (i=0; i<a_rank; i++)
  109.     { sc_times[i] = sc_n[i];
  110.       if (i==0)
  111.          sc_inc [i] = 1;
  112.        else
  113.          sc_inc [i] = sc_inc[i-1] * a_N[i-1];
  114.      }
  115.  
  116.   /* optimize the loops */
  117.  
  118.   sc_loops = a_rank;
  119.   lv = 1;
  120.   while (lv < sc_loops)
  121.     { removed = 0;
  122.       if ( (sc_times[lv-1] * sc_inc[lv-1]) == sc_inc[lv])
  123.          { /* collapse with previous loop , eg. n1 == N1 */
  124.            sc_times [lv-1] *= sc_times[lv];
  125.            removed = 1;
  126.          }
  127.        else if (sc_times[lv] == 1)
  128.          { /* loop with one iteration is unnecessary */
  129.            removed = 1;
  130.          }
  131.       if (removed == 1)
  132.          { /* move next loops back */
  133.            for (i=lv+1; i<sc_loops; i++)
  134.               { sc_times [i-1] = sc_times[i];
  135.                 sc_inc   [i-1] = sc_inc  [i];
  136.               }
  137.            sc_loops -= 1;
  138.          }
  139.        else  /* consider next loop */
  140.          lv += 1;
  141.     }  /* while for traversing loops */
  142.       
  143.    /* note : sc_loops - 1 will later be necessary, first loop has inc 1 */
  144.  
  145.    /* compute the ptr to the first element, e.g.
  146.       sc_ptr  = (x3 * N2 + x2) * N1 + x1  */
  147.  
  148.    sc_ptr = 0;
  149.    for (i = a_rank-1; i >= 0; i--)
  150.       sc_ptr = sc_ptr * a_N[i] + sc_x[i];
  151.  
  152.    /* now set up correctly for later */
  153.  
  154.    sc_length = sc_times[0] * a_size;     /* sc_inc[0] == 1 */
  155.    sc_loops  = sc_loops - 1;
  156.  
  157.    sc_ptr *= a_size;
  158.    for (i=1; i<=sc_loops; i++)
  159.       sc_inc[i] *= a_size;
  160.  
  161. #ifdef DEBUG
  162.    printf ("dalib_section_loops has %d loops\n", sc_loops);
  163.    for (i=1; i<=sc_loops; i++)
  164.       printf ("inc of loop %d = %d\n", i, sc_inc[i]);
  165. #endif
  166.  
  167. } /* dalib_section_loops */
  168.   
  169.  
  170.      /*********************************************************
  171.      *                                                        *
  172.      *  [ 1  2  3  4  my_low ... my_up  .......   ]           *
  173.      *                                                        *
  174.      *  N is then number of all elements                      *
  175.      *                                                        *
  176.      *  (x:y) is the subsection of (my_low:my_up)             *
  177.      *                                                        *
  178.      *********************************************************/
  179.  
  180. void set_range (dim, N, x, y)
  181. int dim, N, x, y;
  182.  
  183. {  sc_x[dim-1] = x;
  184.    sc_y[dim-1] = y;
  185.    a_N [dim-1] = N;
  186. }
  187.  
  188. void localize_range (dim, N, x, y)
  189. int dim, N, x, y;
  190.  
  191. {  int my_low, my_high;
  192.  
  193.    my_low   = ((pcb.i - 1) * N) / pcb.p + 1;
  194.    my_high  = (pcb.i * N) / pcb.p;
  195.  
  196.    sc_x[dim-1] = x - my_low + 1;
  197.    sc_y[dim-1] = y - my_low + 1;
  198.    a_N [dim-1] = my_high - my_low + 1;
  199. }
  200.       
  201.      /*********************************************************
  202.      *                                                        *
  203.      *  SetUp of a local section                              *
  204.      *                                                        *
  205.      *  consider section a(x1:y1,x2:y2,x3:y3,x4:y4) of        *
  206.      *                   whole array a(N1, N2, N3, N4)        *
  207.      *                                                        *
  208.      *  for i4, i3, i2, i1 ...                                *
  209.      *                                                        *
  210.      *  for   times   inc             length                  *
  211.      *    4    n4     (N3-n3)*N2*N1                           *
  212.      *    3    n3     (N2-n2)*N1                              *
  213.      *    2    n2     N1-n1                                   *
  214.      *    1    n1     1                  1                    *
  215.      *                                                        *
  216.      *********************************************************/
  217.  
  218. void dalib_setup_section1 (size, N1, x1, y1)
  219. int size, N1, x1, y1;
  220.  
  221. { /* set global the size of section */
  222.  
  223.   a_rank = 1;
  224.   a_size = size;
  225.  
  226.   localize_range (1, N1, x1, y1);
  227.  
  228.   /* compute the loops for traversing sections */
  229.  
  230.   dalib_section_loops ();
  231.  
  232. #ifdef DEBUG
  233.   printf ("sec: %d ready setup section1: %d elems, len = %d, ptr = %d\n", 
  234.            pcb.i, sc_n[0], sc_length, sc_ptr);
  235. #endif
  236. }
  237.  
  238. void dalib_setup_section2 (size, N1, x1, y1, N2, x2, y2)
  239. int size, N1, x1, y1, N2, x2, y2;
  240.  
  241. { a_rank = 2;
  242.   a_size = size;
  243.  
  244.   /* set global the size of section */
  245.  
  246.   set_range (1, N1, x1, y1);
  247.   localize_range (2, N2, x2, y2);
  248.  
  249.   /* compute the loops for traversing sections */
  250.  
  251.   dalib_section_loops ();
  252.  
  253. #ifdef DEBUG
  254.    printf ("sec: %d setup section2: %d x %d needs %d loops\n",
  255.            pcb.i, sc_n[0], sc_n[1], sc_loops);
  256. #endif
  257. }
  258.  
  259. void dalib_setup_section3 (size, N1, x1, y1, N2, x2, y2, N3, x3, y3)
  260. int size, N1, x1, y1, N2, x2, y2, N3, x3, y3;
  261.  
  262. { a_rank = 3;
  263.   a_size = size;
  264.  
  265.   set_range (1, N1, x1, y1);
  266.   set_range (2, N2, x2, y2);
  267.   localize_range (3, N3, x3, y3);
  268.  
  269.   /* compute the loops for traversing sections */
  270.  
  271.   dalib_section_loops ();
  272.  
  273. #ifdef DEBUG
  274.    printf ("sec: %d setup section3: %d x %d x %d, %d loops\n",
  275.            pcb.i, sc_n[0], sc_n[1], sc_n[2], sc_loops);
  276. #endif
  277. }
  278.  
  279. void dalib_setup_section4 (size, N1, x1, y1, N2, x2, y2, N3, x3, y3, N4, x4, y4)
  280. int size, N1, x1, y1, N2, x2, y2, N3, x3, y3, N4, x4, y4;
  281.  
  282. { a_rank = 4;
  283.   a_size = size;
  284.  
  285.   set_range (1, N1, x1, y1);
  286.   set_range (2, N2, x2, y2);
  287.   set_range (3, N3, x3, y3);
  288.   localize_range (4, N4, x4, y4);
  289.  
  290.   /* compute the loops for traversing sections */
  291.  
  292.   dalib_section_loops ();
  293.  
  294. #ifdef DEBUG
  295.    printf ("sec: %d setup section4: %d x %d x %d x %d, %d loops\n",
  296.            pcb.i, sc_n[0], sc_n[1], sc_n[2], sc_n[3], sc_loops);
  297. #endif
  298. }
  299.  
  300.      /*********************************************************
  301.      *                                                        *
  302.      *  Send of a local section                               *
  303.      *                                                        *
  304.      *********************************************************/
  305.  
  306. void dalib_send_section1 (to, a)
  307. int to;
  308. unsigned char *a;
  309.  
  310. { int from;
  311.   unsigned char *ptr;
  312.  
  313.   /* send section */
  314.  
  315.   from = dalib_pid_ ();
  316.  
  317. #ifdef DEBUG
  318.   printf ("sec: %d sends local (%d-%d) to %d, length = %d, ptr = %d\n",
  319.            from, sc_x[0], sc_y[0], to, sc_length, sc_ptr);
  320. #endif
  321.  
  322.   ptr    = a + sc_ptr;
  323.   asend (from, to, ptr, sc_length);
  324. }
  325.  
  326. void dalib_send_section2 (to, a)
  327. int to;
  328. unsigned char *a;
  329.  
  330. { int i, from;
  331.   unsigned char *ptr;
  332.  
  333.   /* send section */
  334.  
  335.   from = dalib_pid_ ();
  336.  
  337. #ifdef DEBUG
  338.   printf ("sec: %d send2 (%d-%d,%d-%d) to %d, len = %d, lps = %d, ptr = %d\n",
  339.            from, sc_x[0], sc_y[0], sc_x[1], sc_y[1], to,
  340.            sc_length, sc_loops, sc_ptr);
  341. #endif
  342.  
  343.   ptr    = a + sc_ptr;
  344.  
  345.   if (sc_loops == 0)
  346.     { /* continguous section */
  347. #ifdef DEBUG
  348.       printf ("sec: %d now send2, %dx%d, continguous, ptr= %d\n",
  349.               from, sc_n[0], sc_n[1], sc_ptr);
  350. #endif 
  351.       asend (from, to, ptr, sc_length);
  352.     }
  353.    else
  354.     { dalib_create_buffer (sc_size * a_size, 0);
  355. #ifdef DEBUG
  356.       printf ("sec: %d now send2, %dx%d, 1 lps (%d), inc = %d, ptr= %d\n",
  357.               from,sc_n[0],sc_n[1],sc_times[1],sc_inc[1],sc_ptr);
  358. #endif 
  359.       for (i=0;i<sc_times[1];i++)
  360.        {  dalib_fill_buffer (ptr, sc_length);
  361.           ptr += sc_inc[1];
  362.        }
  363.       dalib_send_buffer (to);
  364.       dalib_destroy_buffer ();
  365.     }
  366. }
  367.  
  368. void dalib_send_section3 (to, a)
  369. int to;
  370. unsigned char *a;
  371.  
  372. { int i, j, from;
  373.   unsigned char *ptr;
  374.  
  375.   /* send section */
  376.  
  377.   from = dalib_pid_ ();
  378.  
  379. #ifdef DEBUG
  380.   printf ("%d sends local (%d-%d,%d-%d,%d-%d) to %d, length = %d, ptr = %d\n",
  381.            from,sc_x[0], sc_y[0], sc_x[1], sc_y[1], 
  382.            sc_x[2],sc_y[2], to, sc_length, sc_ptr);
  383. #endif
  384.  
  385.   ptr    = a + sc_ptr;
  386.  
  387.   if (sc_loops == 0)
  388.     { /* continguous section */
  389. #ifdef DEBUG
  390.       printf ("%d send section3, %dx%dx%d, continguous \n",
  391.               from, sc_n[0], sc_n[1], sc_n[2]);
  392. #endif 
  393.       asend (from, to, ptr, sc_length);
  394.     }
  395.    else if (sc_loops == 1)
  396.     { dalib_create_buffer (sc_size * a_size, 0);
  397. #ifdef DEBUG
  398.       printf ("%d send section3, %dx%dx%d, 1 lps (%d), inc = (%d)\n",
  399.               from, sc_n[0], sc_n[1], sc_n[2],
  400.               sc_times[1], sc_inc[1]);
  401. #endif 
  402.       for (i=0;i<sc_times[1];i++)
  403.        {  dalib_fill_buffer (ptr, sc_length);
  404.           ptr += sc_inc[1];
  405.        }
  406.       dalib_send_buffer (to);
  407.       dalib_destroy_buffer ();
  408.     }
  409.    else /* sc_loops == 2 */ 
  410.     { dalib_create_buffer (sc_size * a_size, 0);
  411. #ifdef DEBUG
  412.       printf ("%d send section3, %dx%dx%d, 2 lps (%d,%d), inc = (%d,%d)\n",
  413.               from, sc_n[0], sc_n[1], sc_n[2],
  414.               sc_times[2], sc_times[1], sc_inc[2],sc_inc[1]);
  415. #endif 
  416.       for (i=0;i<sc_times[2];i++)
  417.        { for (j=0;j<sc_times[1];j++)
  418.           {  dalib_fill_buffer (ptr, sc_length);
  419.              ptr += sc_inc[1];
  420.           }
  421.          ptr -= sc_times[1] * sc_inc[1];
  422.          ptr += sc_inc[2];
  423.        }
  424.       dalib_send_buffer (to);
  425.       dalib_destroy_buffer ();
  426.     }
  427. }
  428.  
  429. void dalib_send_section4 (to, a)
  430. int to;
  431. unsigned char *a;
  432.  
  433. { int from;
  434.   unsigned char *ptr;
  435.   int i, j, k;
  436.  
  437.   /* send section */
  438.  
  439.   from = dalib_pid_ ();
  440.  
  441. #ifdef DEBUG
  442.   printf ("sec: %d sends4 (%d-%d,%d-%d,%d-%d,%d-%d) to %d, len=%d, ptr=%d, loops = %d\n",
  443.            from,sc_x[0], sc_y[0], sc_x[1], sc_y[1], 
  444.            sc_x[2],sc_y[2], sc_x[3], sc_y[3], to, sc_length, sc_ptr, sc_loops);
  445. #endif
  446.  
  447.   ptr    = a + sc_ptr;
  448.  
  449.   if (sc_loops == 0)
  450.     { /* continguous section */
  451. #ifdef DEBUG
  452.       printf ("sec: %d now send4, %dx%dx%dx%d, continguous \n",
  453.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3]);
  454. #endif
  455.       asend (from, to, ptr, sc_length);
  456.     }
  457.    else if (sc_loops == 1)
  458.     { dalib_create_buffer (sc_size * a_size, 0);
  459. #ifdef DEBUG
  460.       printf ("sec: %d now send4, %dx%dx%dx%d, 1 loop (%d), inc = (%d)\n",
  461.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  462.               sc_times[1], sc_inc[1]);
  463. #endif
  464.       for (i=0;i<sc_times[1];i++)
  465.        {  dalib_fill_buffer (ptr, sc_length);
  466.           ptr += sc_inc[1];
  467.        }
  468.       dalib_send_buffer (to);
  469.       dalib_destroy_buffer ();
  470.     }
  471.    else if (sc_loops == 2) 
  472.     { dalib_create_buffer (sc_size * a_size, 0);
  473. #ifdef DEBUG
  474.       printf ("sec: %d now send4, %dx%dx%dx%d, 2 lps (%d,%d), inc = (%d,%d)\n",
  475.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  476.               sc_times[2], sc_times[1], sc_inc[2],sc_inc[1]);
  477. #endif
  478.       for (i=0;i<sc_times[2];i++)
  479.        { for (j=0;j<sc_times[1];j++)
  480.           {  dalib_fill_buffer (ptr, sc_length);
  481.              ptr += sc_inc[1];
  482.           }
  483.          ptr -= sc_times[1] * sc_inc[1];
  484.          ptr += sc_inc[2];
  485.        }
  486.       dalib_send_buffer (to);
  487.       dalib_destroy_buffer ();
  488.     }
  489.    else /* sc_loops == 3 */
  490.     { dalib_create_buffer (sc_size * a_size, 0);
  491. #ifdef DEBUG
  492.       printf ("sec: %d now send4, %dx%dx%dx%d, 3lps(%d,%d,%d),inc=(%d,%d,%d)\n",
  493.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  494.               sc_times[3], sc_times[2], sc_times[1], 
  495.               sc_inc[3], sc_inc[2],sc_inc[1]);
  496. #endif
  497.       for (i=0;i<sc_times[3];i++)
  498.        { for (j=0;j<sc_times[2];j++)
  499.           { for (k=0;k<sc_times[1];k++)
  500.              {  dalib_fill_buffer (ptr, sc_length);
  501.                 ptr += sc_inc[1];
  502.              }
  503.             ptr -= sc_times[1] * sc_inc[1];
  504.             ptr += sc_inc[2];
  505.           }
  506.           ptr -= sc_times[2] * sc_inc[2];
  507.           ptr += sc_inc[3];
  508.        }
  509.       dalib_send_buffer (to);
  510.       dalib_destroy_buffer ();
  511.     }
  512. }
  513.  
  514.      /*********************************************************
  515.      *                                                        *
  516.      *  Receive of a local section                            *
  517.      *                                                        *
  518.      *********************************************************/
  519.  
  520. void dalib_recv_section1 (from, a)
  521. int from;
  522. unsigned char *a;
  523.  
  524. { int to;
  525.   unsigned char *ptr;
  526.  
  527.   /* receive section */
  528.  
  529.   to = dalib_pid_ ();
  530.  
  531. #ifdef DEBUG
  532.   printf ("sec: %d recvs local (%d-%d) from %d, length = %d ptr = %d\n",
  533.            to, sc_x[0], sc_y[1], from, sc_length, sc_ptr);
  534. #endif
  535.  
  536.   ptr    = a + sc_ptr;
  537.   areceive (to, from, ptr, sc_length);
  538. }
  539.  
  540. void dalib_recv_section2 (from, a)
  541. int from;
  542. unsigned char *a;
  543.  
  544. { int i, to;
  545.   unsigned char *ptr;
  546.  
  547.   /* receive section */
  548.  
  549.   to = dalib_pid_ ();
  550.  
  551. #ifdef DEBUG
  552.   printf ("sec: %d recvs2 (%d-%d,%d-%d) from %d, len = %d lps = %d ptr = %d\n",
  553.            to, sc_x[0], sc_y[0], sc_x[1], sc_y[1], from, 
  554.            sc_length, sc_loops, sc_ptr);
  555. #endif
  556.  
  557.   ptr    = a + sc_ptr;
  558.   if (sc_loops == 0)
  559.     { /* continguous section */
  560. #ifdef DEBUG
  561.       printf ("sec: %d now recvs2, %dx%d, continguous, ptr = %d \n",
  562.               from, sc_n[0], sc_n[1], sc_ptr);
  563. #endif
  564.       areceive (to, from, ptr, sc_length);
  565.     }
  566.    else
  567.     { dalib_create_buffer (sc_size * a_size, 1);
  568. #ifdef DEBUG
  569.       printf ("sec: %d now recvs2, %dx%d, 1 lps (%d), inc = (%d)\n",
  570.               from, sc_n[0], sc_n[1],
  571.               sc_times[1], sc_inc[1]);
  572. #endif
  573.       dalib_recv_buffer (from);
  574.       for (i=0;i<sc_times[1];i++)
  575.        {  dalib_get_buffer (ptr, sc_length);
  576.           ptr += sc_inc[1];
  577.        }
  578.       dalib_destroy_buffer ();
  579.     }
  580. }
  581.  
  582. void dalib_recv_section3 (from, a)
  583. int from;
  584. unsigned char *a;
  585.  
  586. { int i, j, to;
  587.   unsigned char *ptr;
  588.  
  589.   /* recv section */
  590.  
  591.   to = dalib_pid_ ();
  592.  
  593. #ifdef DEBUG
  594.   printf ("sec: %d recvs (%d-%d,%d-%d,%d-%d) from %d, len = %d ptr = %d\n",
  595.            to, sc_x[0], sc_y[0], sc_x[1], sc_y[1], sc_x[2], sc_y[2],
  596.            from, sc_length, sc_ptr);
  597. #endif
  598.  
  599.   ptr    = a + sc_ptr;
  600.  
  601.   if (sc_loops == 0)
  602.     { /* continguous section */
  603. #ifdef DEBUG
  604.       printf ("sec: %d now recvs3, %dx%dx%d, continguous, ptr = %d \n",
  605.               from, sc_n[0], sc_n[1], sc_n[2], sc_ptr);
  606. #endif
  607.       areceive (to, from, ptr, sc_length);
  608.     }
  609.    else if (sc_loops == 1)
  610.     { dalib_create_buffer (sc_size * a_size, 1);
  611.       dalib_recv_buffer (from);
  612. #ifdef DEBUG
  613.       printf ("sec: %d now recvs3, %dx%dx%d, 1 lps (%d), inc = (%d)\n",
  614.               to, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  615.               sc_times[1], sc_inc[1]);
  616. #endif 
  617.       for (i=0;i<sc_times[1];i++)
  618.        {  dalib_get_buffer (ptr, sc_length);
  619.           ptr += sc_inc[1];
  620.        }
  621.       dalib_destroy_buffer ();
  622.     }
  623.    else /* sc_loops == 2 */
  624.     { dalib_create_buffer (sc_size * a_size, 1);
  625.       dalib_recv_buffer (from);
  626. #ifdef DEBUG
  627.       printf ("sec: %d now recvs3, %dx%dx%d, 2 lps (%d,%d), inc = (%d,%d)\n",
  628.               to, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  629.               sc_times[2], sc_times[1], sc_inc[2], sc_inc[1]);
  630. #endif 
  631.       for (i=0;i<sc_times[2];i++)
  632.        { for (j=0;j<sc_times[1];j++)
  633.           {  dalib_get_buffer (ptr, sc_length);
  634.              ptr += sc_inc[1];
  635.           }
  636.          ptr -= sc_times[1] * sc_inc[1];
  637.          ptr += sc_inc[2];
  638.        }
  639.       dalib_destroy_buffer ();
  640.     }
  641. }
  642.  
  643. void dalib_recv_section4 (from, a)
  644. int from;
  645. unsigned char *a;
  646.  
  647. { int to;
  648.   unsigned char *ptr;
  649.   int i, j, k;
  650.  
  651.   /* recv section */
  652.  
  653.   to = dalib_pid_ ();
  654.  
  655. #ifdef DEBUG
  656.   printf ("sec: %d recvs4 (%d-%d,%d-%d,%d-%d,%d-%d) from %d, len=%d, ptr=%d\n",
  657.            to, sc_x[0], sc_y[0], sc_x[1], sc_y[1],
  658.            sc_x[2],sc_y[2], sc_x[3], sc_y[3], from, sc_length, sc_ptr);
  659. #endif
  660.  
  661.   ptr    = a + sc_ptr;
  662.  
  663.   if (sc_loops == 0)
  664.     { /* continguous section */
  665. #ifdef DEBUG
  666.       printf ("sec: %d now rec4, %dx%dx%dx%d, continguous \n",
  667.               to, sc_n[0], sc_n[1], sc_n[2], sc_n[3]);
  668. #endif
  669.       areceive (to, from, ptr, sc_length);
  670.     }
  671.    else if (sc_loops == 1)
  672.     { dalib_create_buffer (sc_size * a_size, 1);
  673.       dalib_recv_buffer (from);
  674. #ifdef DEBUG
  675.       printf ("sec: %d now rec4, %dx%dx%dx%d, 1 loop (%d), inc = (%d)\n",
  676.               to, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  677.               sc_times[1], sc_inc[1]);
  678. #endif
  679.       for (i=0;i<sc_times[1];i++)
  680.        {  dalib_get_buffer (ptr, sc_length);
  681.           ptr += sc_inc[1];
  682.        }
  683.       dalib_destroy_buffer ();
  684.     }
  685.    else if (sc_loops == 2)
  686.     { dalib_create_buffer (sc_size * a_size, 1);
  687.       dalib_recv_buffer (from);
  688. #ifdef DEBUG
  689.       printf ("sec: %d now rec4, %dx%dx%dx%d, 2 lps (%d,%d), inc = (%d,%d)\n",
  690.               to, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  691.               sc_times[2], sc_times[1], sc_inc[2],sc_inc[1]);
  692. #endif
  693.       for (i=0;i<sc_times[2];i++)
  694.        { for (j=0;j<sc_times[1];j++)
  695.           {  dalib_get_buffer (ptr, sc_length);
  696.              ptr += sc_inc[1];
  697.           }
  698.          ptr -= sc_times[1] * sc_inc[1];
  699.          ptr += sc_inc[2];
  700.        }
  701.       dalib_destroy_buffer ();
  702.     }
  703.    else /* sc_loops == 3 */
  704.     { dalib_create_buffer (sc_size * a_size, 1);
  705.       dalib_recv_buffer (from);
  706. #ifdef DEBUG
  707.       printf ("sec: %d recv4, %dx%dx%dx%d, 3 lps(%d,%d,%d), inc=(%d,%d,%d)\n",
  708.               to, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  709.               sc_times[3], sc_times[2], sc_times[1],
  710.               sc_inc[3], sc_inc[2],sc_inc[1]);
  711. #endif
  712.       for (i=0;i<sc_times[3];i++)
  713.        { for (j=0;j<sc_times[2];j++)
  714.           { for (k=0;k<sc_times[1];k++)
  715.              {  dalib_get_buffer (ptr, sc_length);
  716.                 ptr += sc_inc[1];
  717.              }
  718.             ptr -= sc_times[1] * sc_inc[1];
  719.             ptr += sc_inc[2];
  720.           }
  721.           ptr -= sc_times[2] * sc_inc[2];
  722.           ptr += sc_inc[3];
  723.        }
  724.       dalib_destroy_buffer ();
  725.     }
  726. }
  727.  
  728.      /*********************************************************
  729.      *                                                        *
  730.      *  Copy of a local section to a new array                *
  731.      *                                                        *
  732.      *********************************************************/
  733.  
  734. void dalib_copy_section1 (to, a)
  735. unsigned char *to;
  736. unsigned char *a;
  737.  
  738. { unsigned char *ptr;
  739.  
  740.   /* copy section */
  741.  
  742. #ifdef DEBUG
  743.   int from;
  744.   from = pcb.i;
  745.   printf ("sec: %d copies local (%d-%d) to %d, length = %d, ptr = %d\n",
  746.            from, sc_x[0], sc_y[0], to, sc_length, sc_ptr);
  747. #endif
  748.  
  749.   ptr    = a + sc_ptr;
  750.   dalib_memcpy (to, ptr, sc_length);
  751. }
  752.  
  753. void dalib_copy_section2 (to, a)
  754. unsigned char *to;
  755. unsigned char *a;
  756.  
  757. { int i;
  758.   unsigned char *ptr, *to_ptr;
  759.  
  760.   /* copy section */
  761.  
  762. #ifdef DEBUG
  763.   int from;
  764.   from = pcb.i;
  765.   printf ("sec: %d copy2 (%d-%d,%d-%d) to %d, len = %d, lps = %d, ptr = %d\n",
  766.            from, sc_x[0], sc_y[0], sc_x[1], sc_y[1], to,
  767.            sc_length, sc_loops, sc_ptr);
  768. #endif
  769.  
  770.   ptr    = a + sc_ptr;
  771.  
  772.   if (sc_loops == 0)
  773.     { /* continguous section */
  774. #ifdef DEBUG
  775.       printf ("sec: %d now copy2, %dx%d, continguous, ptr= %d\n",
  776.               from, sc_n[0], sc_n[1], sc_ptr);
  777. #endif 
  778.       dalib_memcpy (to, ptr, sc_length);
  779.     }
  780.    else
  781.     { to_ptr = to;
  782. #ifdef DEBUG
  783.       printf ("sec: %d now copy2, %dx%d, 1 lps (%d), inc = %d, ptr= %d\n",
  784.               from,sc_n[0],sc_n[1],sc_times[1],sc_inc[1],sc_ptr);
  785. #endif 
  786.       for (i=0;i<sc_times[1];i++)
  787.        {  dalib_memcpy (to_ptr, ptr, sc_length);
  788.           ptr += sc_inc[1];
  789.           to_ptr += sc_length;
  790.        }
  791.     }
  792. }
  793.  
  794. void dalib_copy_section3 (to, a)
  795. unsigned char *to;
  796. unsigned char *a;
  797.  
  798. { int i, j, from;
  799.   unsigned char *ptr, *to_ptr;
  800.  
  801.   /* send section */
  802.  
  803.   from = dalib_pid_ ();
  804.  
  805. #ifdef DEBUG
  806.   printf ("%d copy3 local (%d-%d,%d-%d,%d-%d) to %d, length = %d, ptr = %d\n",
  807.            from,sc_x[0], sc_y[0], sc_x[1], sc_y[1], 
  808.            sc_x[2],sc_y[2], to, sc_length, sc_ptr);
  809. #endif
  810.  
  811.   ptr    = a + sc_ptr;
  812.  
  813.   if (sc_loops == 0)
  814.     { /* continguous section */
  815. #ifdef DEBUG
  816.       printf ("%d copy section3, %dx%dx%d, continguous \n",
  817.               from, sc_n[0], sc_n[1], sc_n[2]);
  818. #endif 
  819.       dalib_memcpy (to, ptr, sc_length);
  820.     }
  821.    else if (sc_loops == 1)
  822.     { to_ptr = to;
  823. #ifdef DEBUG
  824.       printf ("%d copy section3, %dx%dx%d, 1 lps (%d), inc = (%d)\n",
  825.               from, sc_n[0], sc_n[1], sc_n[2],
  826.               sc_times[1], sc_inc[1]);
  827. #endif 
  828.       for (i=0;i<sc_times[1];i++)
  829.        {  dalib_memcpy (to_ptr, ptr, sc_length);
  830.           ptr += sc_inc[1];
  831.           to_ptr += sc_length;
  832.        }
  833.     }
  834.    else /* sc_loops == 2 */ 
  835.     { to_ptr = to;
  836. #ifdef DEBUG
  837.       printf ("%d copy section3, %dx%dx%d, 2 lps (%d,%d), inc = (%d,%d)\n",
  838.               from, sc_n[0], sc_n[1], sc_n[2],
  839.               sc_times[2], sc_times[1], sc_inc[2],sc_inc[1]);
  840. #endif 
  841.       for (i=0;i<sc_times[2];i++)
  842.        { for (j=0;j<sc_times[1];j++)
  843.           {  dalib_memcpy (to_ptr, ptr, sc_length);
  844.              ptr += sc_inc[1];
  845.              to_ptr += sc_length;
  846.           }
  847.          ptr -= sc_times[1] * sc_inc[1];
  848.          ptr += sc_inc[2];
  849.        }
  850.     }
  851. }
  852.  
  853. void dalib_copy_section4 (to, a)
  854. unsigned char *to;
  855. unsigned char *a;
  856.  
  857. { int from;
  858.   unsigned char *ptr, *to_ptr;
  859.   int i, j, k;
  860.  
  861.   /* send section */
  862.  
  863.   from = dalib_pid_ ();
  864.  
  865. #ifdef DEBUG
  866.   printf ("sec: %d copy4 (%d-%d,%d-%d,%d-%d,%d-%d) to %d, len=%d, ptr=%d, loops = %d\n",
  867.            from,sc_x[0], sc_y[0], sc_x[1], sc_y[1], 
  868.            sc_x[2],sc_y[2], sc_x[3], sc_y[3], to, sc_length, sc_ptr, sc_loops);
  869. #endif
  870.  
  871.   ptr    = a + sc_ptr;
  872.  
  873.   if (sc_loops == 0)
  874.     { /* continguous section */
  875. #ifdef DEBUG
  876.       printf ("sec: %d now copy4, %dx%dx%dx%d, continguous \n",
  877.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3]);
  878. #endif
  879.       dalib_memcpy (to, ptr, sc_length);
  880.     }
  881.    else if (sc_loops == 1)
  882.     { to_ptr = to;
  883. #ifdef DEBUG
  884.       printf ("sec: %d now copy4, %dx%dx%dx%d, 1 loop (%d), inc = (%d)\n",
  885.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  886.               sc_times[1], sc_inc[1]);
  887. #endif
  888.       for (i=0;i<sc_times[1];i++)
  889.        {  dalib_memcpy (to_ptr, ptr, sc_length);
  890.           ptr += sc_inc[1];
  891.           to_ptr += sc_length;
  892.        }
  893.     }
  894.    else if (sc_loops == 2) 
  895.     { to_ptr = to;
  896. #ifdef DEBUG
  897.       printf ("sec: %d now copy4, %dx%dx%dx%d, 2 lps (%d,%d), inc = (%d,%d)\n",
  898.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  899.               sc_times[2], sc_times[1], sc_inc[2],sc_inc[1]);
  900. #endif
  901.       for (i=0;i<sc_times[2];i++)
  902.        { for (j=0;j<sc_times[1];j++)
  903.           {  dalib_memcpy (to_ptr, ptr, sc_length);
  904.              ptr += sc_inc[1];
  905.              to_ptr += sc_length;
  906.           }
  907.          ptr -= sc_times[1] * sc_inc[1];
  908.          ptr += sc_inc[2];
  909.        }
  910.     }
  911.    else /* sc_loops == 3 */
  912.     { to_ptr = to;
  913. #ifdef DEBUG
  914.       printf ("sec: %d now copy4, %dx%dx%dx%d, 3lps(%d,%d,%d),inc=(%d,%d,%d)\n",
  915.               from, sc_n[0], sc_n[1], sc_n[2], sc_n[3],
  916.               sc_times[3], sc_times[2], sc_times[1], 
  917.               sc_inc[3], sc_inc[2],sc_inc[1]);
  918. #endif
  919.       for (i=0;i<sc_times[3];i++)
  920.        { for (j=0;j<sc_times[2];j++)
  921.           { for (k=0;k<sc_times[1];k++)
  922.              {  dalib_memcpy (to_ptr, ptr, sc_length);
  923.                 ptr += sc_inc[1];
  924.                 to_ptr += sc_length;
  925.              }
  926.             ptr -= sc_times[1] * sc_inc[1];
  927.             ptr += sc_inc[2];
  928.           }
  929.           ptr -= sc_times[2] * sc_inc[2];
  930.           ptr += sc_inc[3];
  931.        }
  932.     }
  933. }
  934.